package ArrayList;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

class Book {

}


public class Test {
    public static void main(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);

        System.out.println(list);

        System.out.println("======for循环========");
        for (int i = 0; i < list.size(); i++) {//List是动态数据结构，使用size()方法来获取其中元素的数量。
            System.out.print(list.get(i) + " ");
        }
        System.out.println();

        System.out.println("======foreach循环========");
        for (Integer x : list) {
            System.out.print(x + " ");
        }
        System.out.println();

        System.out.println("======迭代器遍历1========");
        Iterator<Integer> list1 = list.iterator();
        while (list1.hasNext()) {
            System.out.print(list1.next() + " ");
        }
        System.out.println();
        System.out.println("======迭代器遍历2========");
        ListIterator<Integer> list2 = list.listIterator();
        while (list2.hasNext()) {
            System.out.print(list2.next() + " ");
        }
        System.out.println();

        System.out.println("======迭代器遍历3========");
        ListIterator<Integer> prevlist3 = list.listIterator(list.size());
        while(prevlist3.hasPrevious()){
            System.out.print(prevlist3.previous()+ " ");
        }
        System.out.println();

    }

    public static void main2(String[] args) {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);
        list.add(4);
        System.out.println(list);

        List<Integer> listTmp = list.subList(1, 3);
        System.out.println(listTmp);
        System.out.println("=======================");
        listTmp.set(0, 99);
        System.out.println(listTmp);
        System.out.println(list);

        /*list.remove(new Integer(1));
        System.out.println(list);*/
        //list.addAll(list);

        /*list<Integer> listTmp = list.subList(1,3);// 2 3
        System.out.println(listTmp);
        System.out.println("=====================");
        listTmp.set(0,99);
        System.out.println("listTmp： "+listTmp);
        System.out.println("list: "+ list);*/
    }


    public static void main1(String[] args) {
        //ArrayList<Integer> list = new ArrayList<>();
        ArrayList<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);
        list.add(3);


        list.add(1, 7);

        ArrayList<Book> booksList = new ArrayList<>();
    }

}
